package com.example.sxt_practise.thread;

/**
 * 线程变成就绪状态
 * 礼让:不一定成功
 * @author gaofeng
 * @date 2022年05月25日 22:39
 */
public class ThreadYieldTest {
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(new YieldThread(), "a");


        Thread thread2 = new Thread(new YieldThread(), "b");
        System.out.println(thread1.getState());
        thread1.start();
        Thread.sleep(2000);
        thread2.join();
        thread2.start();
        System.out.println(thread1.getState());
    }
}

class YieldThread implements Runnable {

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "正在运行");
    }
}
